package com.icbc.open.chengdu.demo.account.query;

import com.icbc.api.DefaultIcbcClient;
import com.icbc.api.internal.util.internal.util.fastjson.JSON;
import com.icbc.api.request.SettlementAccountOpenQueryRequestV1;
import com.icbc.api.response.SettlementAccountOpenQueryResponseV1;
import com.icbc.open.chengdu.demo.BaseData;
import com.icbc.open.chengdu.demo.utils.SaveFileUtils;
import com.icbc.open.chengdu.demo.utils.SecretUtils;

/**
 * 开销户或绑卡申请订单查询
 * 提供合作方对我行结算账户开户、销户、绑卡申请查询结果的功能(仅支持14天以内含14天的数据查询)
 *
 * @author xcz
 */
public class SettlementAccountOpenQueryTest {


    public static void main(String[] args) throws Exception {
        DefaultIcbcClient client = new DefaultIcbcClient(BaseData.APP_ID, BaseData.MY_RSA_PRIVATE_KEY, BaseData.ICBC_RSA_PUBLIC_KEY);
        SettlementAccountOpenQueryRequestV1 request = new SettlementAccountOpenQueryRequestV1();
        SettlementAccountOpenQueryRequestV1.SettlementAccountOpenQueryRequestV1Biz bizContent = new SettlementAccountOpenQueryRequestV1.SettlementAccountOpenQueryRequestV1Biz();
        request.setServiceUrl(BaseData.ACCOUNT_OPEN_QUERY_URL);//API地址
        bizContent.setCorpNo(BaseData.APP_ID); //合作方机构编号
        bizContent.setOutServiceCode("queryopenbook"); //外部服务代码
        //bizContent.setOpenCorpSerno(SaveFileUtils.getOpenAccount()); //原合作方交易单号  开户
        //bizContent.setOpenCorpSerno(SaveFileUtils.getCloseAccount()); //原合作方交易单号  销户
        bizContent.setOpenCorpSerno(SaveFileUtils.getBindMedium());//原合作方交易单号  绑定
        request.setBizContent(bizContent);
        SettlementAccountOpenQueryResponseV1 response = client.execute(request);
        System.out.println(JSON.toJSONString(response));
        if (response.isSuccess() && response.getReturnCode() == 0) {
            //成功
            System.out.println("II类卡号：" + SecretUtils.decryptMediumId(response.getMediumId(), response.getSecretKey()));
        } else {
            //失败
        }
    }
}
